<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .lb{
            width: 300px;
            height: 500px;
            background-image: url(img/1.JPG);
            background-size: 100% 100%;
        }
    </style>
</head>
<body>
    <div class="lb">

    <button onclick="lunbo1()">上一张</button>
    <button onclick="lunbo2()">下一张</button>
    <script>
        let index = 1
        function lunbo2(){
            index++;
            if(index>3){
                index= 1
            }
            var img =document.getElementsByClassName("lb")[0]
            img.style.background="url(img/"+index+".JPG)";
            img.style.backgroundSize="100% 100%"
        }
       
        function lunbo1(){
            index--;
            if(index<1){
                index= 3
            }
            var img =document.getElementsByClassName("lb")[0]
            img.style.background="url(img/"+index+".JPG)";
            img.style.backgroundSize="100% 100%"
        }
    </script>
</body>
</html>